package contest.co6139;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
    int count=0;
    Set<Integer> vis=new HashSet<>();
    public int reachableNodes(int n, int[][] edges, int[] restricted) {
        Node[] nodes=new Node[n];
        for (int i = 0; i < n; i++) {
            nodes[i]=new Node(i);

        }
        for (int e:restricted){
            vis.add(e);
        }
        for (int[] edge : edges) {
            nodes[edge[0]].children.add(nodes[edge[1]]);
            nodes[edge[1]].children.add(nodes[edge[0]]);
        }
        dfs(nodes[0]);
        return count;
    }
    public void dfs(Node node){
        count++;
        vis.add(node.ID);
        for (Node node1: node.children){
            if (!vis.contains(node1.ID)){
                dfs(node1);
            }
        }
    }

}
class Node{
    int ID;
    List<Node> children=new ArrayList<>();

    public Node(int ID) {
        this.ID = ID;
    }
}